package aaa;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;
import java.util.ResourceBundle;

public class a {
    public static void main(String[] args) throws SQLException, IOException {
        //注册驱动
//        Driver driver = new com.mysql.cj.jdbc.Driver();//创建核心驱动对象
//        DriverManager.registerDriver(driver);//注册驱动

        //获取连接
//        String url="jdbc:mysql://localhost:3306/jdbc";
//        String user ="root";
//        String password ="123456";

//        ResourceBundle bundle = ResourceBundle.getBundle("aaa.jdbc");
//        ResourceBundle bundle = ResourceBundle.getBundle("aaa.jdbc");
       // InputStream fileInputStream = new FileInputStream("D:\\IEDAFile\\JavaWeb\\jdbc\\src\\main\\java\\aaa\\jdbc.properties");
        InputStream fileInputStream = new FileInputStream("jdbc/src/main/java/aaa/jdbc.properties");

        Properties properties = new Properties();
        properties.load(fileInputStream);
//        properties.list(System.out);



//
//        String driver = bundle.getString("driver");
//        String url = bundle.getString("url");
//        String user = bundle.getString("username");
//        String password = bundle.getString("password");
        String driver = properties.getProperty("driver");
        String url = properties.getProperty("url");
        String user =properties.getProperty("username");
        String password = properties.getProperty("password");

        Connection connection = DriverManager.getConnection(url, user, password);

//        System.out.println(connection);
        //获取数据库操作对象
//        Statement statement = connection.createStatement();
//        Statement statement1 = connection.createStatement();
//        System.out.println(statement);
////        System.out.println(statement1);
        String sql="delete from t_user where realname = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, "hah");
        int i = preparedStatement.executeUpdate();
        System.out.println(i+"条记录被删除了");



        // boolean execute = statement.execute(sql);
//        int i = statement.executeUpdate(sql);
//        String sql="select * from t_user";
//        ResultSet resultSet = statement.executeQuery(sql);
//        System.out.println(i);
//        int i = statement.executeUpdate(sql, statement.RETURN_GENERATED_KEYS);
//        ResultSet generatedKeys = statement.getGeneratedKeys();
//        if(generatedKeys.next()){
//            System.out.println(generatedKeys.getInt(1));
//        }


//        while(resultSet.next()){
//
//            System.out.println(resultSet.getString(1));
//            System.out.println(resultSet.getString(2));
//            System.out.println(resultSet.getString(3));
//            System.out.println(resultSet.getString(4));
//            System.out.println("---------------------------");
//
////            System.out.println(resultSet.getString("id"));
////            System.out.println(resultSet.getString("name"));
////            System.out.println(resultSet.getString("password"));
////            System.out.println(resultSet.getString("realname"));
////            System.out.println(resultSet.getString("gender"));
////            System.out.println(resultSet.getString("tel"));
////            System.out.println("------------------------------------------");
//
//        }
//        resultSet.close();
        preparedStatement.close();
        connection.close();




    }

}
